package com.itheima.reggie.controller;

import com.itheima.reggie.common.PageResult;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    private R<String> submit(@RequestBody Orders orders) {
        log.info("订单数据:{}", orders);
       // payController.alipay(orders);
       orderService.submit(orders);
        return R.success("下单成功");
    }
    /**
     * 历史订单查看
     */
    @GetMapping("/userPage")
    public R<PageResult> findPage(@RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pageSize", defaultValue = "10") Long pageSize) {
        PageResult<DishDto> pageResult = orderService.findPage(page, pageSize);
        return R.success(pageResult);
    }

    /**
     * 后端查询订单分页
     */
    @GetMapping("/page")
    public R all(@RequestParam("page") Long page, @RequestParam(value = "pageSize") Long pagesize, @RequestParam(value = "number", required = false) String number,
                 @RequestParam(value = "beginTime", required = false) String beginTime, @RequestParam(value = "endTime", required = false) String endTime) {
        R all = orderService.All(page, pagesize, number, beginTime, endTime);
        return orderService.All(page, pagesize, number, beginTime, endTime);
    }

    /**
     * 订单状态更新
     */
    @PutMapping
    public R<String> update(@RequestBody Orders orders){
        String msg = orderService.updateStatus(orders);
        return R.success(msg);
    }


}
